<!DOCTYPE html>
<html>

<head>
    <meta charset=utf-8>
    <meta http-equiv=X-UA-Compatible content="IE=edge">
    <meta name=viewport content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <meta name=format-detection content="telephone=no">
    <title>有道词典</title>
    <script type=text/javascript src=../js/weblibs.js></script>
    <script type=text/javascript src=../js/vendor.dll.js></script>
    <script type=text/javascript src="./socket-translate.js"></script>
    <link href=../css/app.css rel=stylesheet>
</head>

<body>
    <div id=app>
        <router-view></router-view>
    </div>
    <div id="logger" style="position: fixed;top: 0;left: 0;
        background-color: rgba(0, 0, 0, 0.5);
        border: 1px solid lightgray;
        overflow: hidden;
        /* display: none; */
        width: 15px;height: 22px;" ondblclick="logger_close()">
        <div style="position: absolute;top: 0;left: 0;
        width: 100%;
        height: 25px;
        line-height: 25px;
        border: 1px solid lightgray;">
            <input id="logger-command" type="text" value="c" />
            <button title="
            c: clean
            ...
            " onclick="logger_command()">>></button>
        </div>
        <div id="logger-content" style="margin-top: 25px;
        width: 100%;height: 95%;overflow: auto;"></div>
    </div>
    <script>
        var logger = document.getElementById('logger');
        var loggerCommand = document.getElementById('logger-command');
        var loggerContent = document.getElementById('logger-content');
        var logger_append = true;

        function logger_close() {
            // logger.style.display = 'none';
            if (logger.offsetWidth > 20) {
                logger.style.width = "15px";
                logger.style.height = "22px";
            } else {
                logger.style.width = "100%";
                logger.style.height = "100%";
            }

        }

        function logger_command() {
            var c = loggerCommand.value;
            switch (c) {
                case ("c"):
                    loggerContent.innerHTML = "";
                    break;
                default:
                    wurd_translate(c);
                    break;
            }
        }

        function wurd_translate(keyword) {
            keyword = keyword ? keyword : "you are my love";
            var dd = {
                "keyword": keyword,
                "from": "en",
                "to": "zh-CHS",
                "keyfrom": "deskdict.main",
                "forTranslatePage": true,
                "type": "local"
            };
            var ddd = {
                data: dd,
                complete: null,
                fail: function(e) {
                    doLog("fail:", e);
                },
                success: function(e) {
                    doLog("success:", e);
                }
            };
            ydk.getTranslateResult(ddd)
        }

        function doLog() {
            var message = "";
            try {
                for (var argI = 0; argI < arguments.length; argI++) {
                    var msg = arguments[argI];
                    msg = formatLog(msg);
                    message = message + msg + "<br/><br/>";
                }
            } catch (error) {
                message = "doLog error: " + error;
            }

            function formatLog(msg) {
                if (typeof msg == 'object') {
                    var cache = [];
                    var depth = 20;
                    msg = JSON.stringify(msg, function(key, value) {
                        depth = depth - 1;
                        if (typeof value === 'object' && value !== null) {
                            if (depth < 0 || cache.indexOf(value) !== -1) {
                                return;
                            }
                            cache.push(value);
                        }
                        if (value instanceof Function) {
                            return value.toString().substr(0, 50);
                        } else {
                            return value;
                        }
                    });
                    cache = null;
                }
                return msg;
            }
            if (logger_append) {
                var exitMsg = loggerContent.innerHTML;
                message = exitMsg + "<br/><br/>" + message;
            }
            loggerContent.innerHTML = message;
            logger.style.display = 'block';
        }
    </script>
    <script type=text/javascript src=../js/app.js></script>
</body>

</html>